<?php
namespace Admin\Controller;
use Think\Controller;
class ShopController extends BaseController {
    
	protected function _initialize(){
		parent::_initialize();
	}
	
	//店铺管理
	public function index(){
		//
	}
	
	//店铺列表
	public function shoplist(){
		$m=M('bb_shop');
		$p=$_GET['p']?$_GET['p']:1;
		$psize=C('BB_PSIZE')?C('BB_PSIZE'):20;
		
		$map='';
		$data=$m->where($map)->page($p,$psize)->order('createTm desc')->select();
		$count=$m->where($map)->count();
		$this->getPage($count, $psize, 'bb-loader', '店铺管理','bb-search');
		foreach ($data as $k => $v){
			
		}
		$this->assign('cache',$data);
		$this->display();
	}
	
	//修改店铺数据
	public function shopset(){
		$id=I('id');
		$m=M('bb_shop');
		if(IS_POST){
			$p=I('post.');
			$re=$m->save($p);
			if($re){
				$info['status']=1;
				$info['msg']='修改成功!';
			}else{
				$info['status']=0;
				$info['msg']='修改失败!';
			}
			$this->ajaxreturn($info);
		}
		if($id){
			$cache=$m->where('id='.$id)->find();
			$this->assign('cache',$cache);
		}
		$this->display();
	}
	//店员列表
	public function shopuser(){
		$m=M('bps_shop_user');
		$p=$_GET['p']?$_GET['p']:1;
		$psize=C('BB_PSIZE')?C('BB_PSIZE'):20;
		$map='';
		$data=$m->where($map)->page($p,$psize)->order('creatTm desc')->select();
		$count=$m->where($map)->count();
		$this->getPage($count, $psize, 'bb-loader', '店铺管理','bb-search');
		foreach ($data as $k => $v){
			
		}
		//p($data);
		$this->assign('cache',$data);
		$this->display();
	}
	//删除店铺
	public function shopdel(){
		$id=I('id');
		if($id){
			$re=M('bb_shop')->delete($id);
			if($re){
				$info['status']=1;
				$info['msg']='删除成功!';
			}else{
				$info['status']=0;
				$info['msg']='删除失败!';
			}
			$this->ajaxreturn($info);
		}
	}
	
	
	//
	public function auntie(){
		$id=I('id');
		if($id){
			echo '<a id="alink" href="'.U('Admin/Auntie/auntieset',array('id'=>$id)).'" data-loader="bb-loader" data-loadername=""></a>'; 
			echo "<script>initLoader('bb-loader'); setTimeout(function(){ document.getElementById('alink').click(); },1000); </script>";
			exit;
		}
	}
	
	
	public function shopcx(){
		if(!$_GET['term']){
			$this->error('无搜索条件！');
		}
		
		$arr = M('bb_shop');
		;
		switch ($_GET['term'])
		{
		case 1:
		  $map['name'] = array('like',$_GET['key']);
		  $arr->where('')->select();
		  break;  
		case 2:
		  code to be executed if expression = label2;
		  break;
		default:
		  code to be executed
		  if expression is different 
		  from both label1 and label2;
		}
		
		
		
	}
	
	
}